package com.nf.health.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.MapVo;
import com.nf.health.app.utils.Util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 健康方案  gridView 适配器
 * Created by Administrator on 2016/3/24.
 */
public class GridViewAdapter extends BaseAdapter {


    String week;

    List<MapVo> mlist_gridview;

    private Context context;

    public GridViewAdapter(List<MapVo> mlist_gridview, Context context) {
        this.mlist_gridview = mlist_gridview;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mlist_gridview == null ? 0 : mlist_gridview.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist_gridview.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_gridview, position);

        TextView grid_view_value = holder.getView(R.id.grid_view_value);
        ImageView grid_view_image = holder.getView(R.id.grid_view_image);




        String[] nn1 = mlist_gridview.get(position).getData().split("-");


        if (mlist_gridview.get(position).getValue().equals("2")) {
            grid_view_image.setImageResource(R.drawable.yuan_image_y);
        } else if (mlist_gridview.get(position).getValue().equals("1")) {
            grid_view_image.setImageResource(R.drawable.yuan_image_w);
        } else if (mlist_gridview.get(position).getValue().equals("0")) {
            grid_view_image.setVisibility(View.INVISIBLE);
        }

        if(TextUtils.isEmpty(mlist_gridview.get(position).getData())){
            grid_view_value.setText(mlist_gridview.get(position).getData());//
            grid_view_image.setVisibility(View.INVISIBLE);
        }else{
            if (nn1[2].equals("01")) {
                grid_view_value.setText(nn1[1].replace("0", "") + "月");//
            }else{
                grid_view_value.setText(nn1[2]);//
            }
        }



        return holder.getConvertView();
    }

}